package mapreduce.old;

import java.io.IOException;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.io.compress.GzipCodec;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

public class MaxTemperatureWithCompression {
	public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException {

		Configuration conf = new Configuration();
		conf.addResource(System.getProperty("hadoop.demo.conf") + "/core-site.xml");
		conf.addResource(System.getProperty("hadoop.demo.conf") + "/hdfs-site.xml");
		conf.addResource(System.getProperty("hadoop.demo.conf") + "/mapred-site.xml");
		conf.addResource(System.getProperty("hadoop.demo.conf") + "/yarn-site.xml");
		conf.set("hadoop.job.ugi", "hadoop,supergroup,hadoop");
		// conf.set("mapreduce.framework.name", "YOUR MACH");
		// conf.set("yarn.resourcemanager.address", "YOUR IP:8032");
		Job job = Job.getInstance(conf);
		job.setJarByClass(MaxTemperatureWithCompression.class);
		/**
		 * 确定输入输出文件路径
		 */
		FileInputFormat.addInputPath(job, new Path(args[0]));
		FileOutputFormat.setOutputPath(job, new Path(args[1]));
		/**
		 * 确定输出格式
		 */
		job.setOutputKeyClass(Text.class);
		job.setOutputValueClass(IntWritable.class);
		/**
		 * 设置压缩
		 */
		FileOutputFormat.setCompressOutput(job, true);
		FileOutputFormat.setOutputCompressorClass(job, GzipCodec.class);
		job.setMapperClass(MaxTemperatureMapper.class);
		job.setCombinerClass(MaxTemperatureReducer.class);
		job.setReducerClass(MaxTemperatureReducer.class);
		System.exit(job.waitForCompletion(true) ? 0 : 1);
	}
}
